export interface AxiosRequestConfig {
  url?: string
  method?: Method
  data?: any
  params?: any
  headers?: any
  timeout?: number
  // 用于判断判断响应数据类型
  responseType?: XMLHttpRequestResponseType
}

// 定义method取值范围
export type Method =
  | 'get'
  | 'GET'
  | 'delete'
  | 'Delete'
  | 'head'
  | 'HEAD'
  | 'options'
  | 'OPTIONS'
  | 'post'
  | 'POST'
  | 'put'
  | 'PUT'
  | 'patch'
  | 'PATCH'

// 定义响应数据接口
export interface AxiosResponse {
  data: any
  status: number
  statusText: string
  headers: any
  config: AxiosRequestConfig
  // 请求头信息
  request: any
}

// 整个泛型接口意思是 AxiosPromise需要接受一个AxiosResponse的promise对象
export interface AxiosPromise extends Promise<AxiosResponse> {}

// 错误信息增强接口
export interface AxiosError extends Error {
  config: AxiosRequestConfig
  code?: string
  request?: any
  response?: AxiosResponse
  isAxiosError: boolean
}

// 定义混合对象axios接口
export interface Axios {
  request(config: AxiosRequestConfig): AxiosPromise

  get(url: string, config?: AxiosRequestConfig): AxiosPromise

  delete(url: string, config?: AxiosRequestConfig): AxiosPromise

  head(url: string, config?: AxiosRequestConfig): AxiosPromise

  options(url: string, config?: AxiosRequestConfig): AxiosPromise

  post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise

  put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise

  patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise
}
// 利用extends 继承Axios接口，实现混合对象
export interface AxiosInstance extends Axios {
  (config: AxiosRequestConfig): AxiosPromise

  // 函数扩展方法 支持传入两个参数
  (url: string, config?: AxiosRequestConfig): AxiosPromise
}
